package com.zb.test;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class RoutingKeyPro {

	private static final String QUEUE_QQ = "QQ";

	private static final String QUEUE_WEIXIN = "WEIXIN";

	private static final String EXCHANGE_ROUTING = "EXCHANGE_ROUTING";

	private static final String RUOTING_KEY = "RUOTING_KEY";

	private static final ConnectionFactory factory = new ConnectionFactory();

	private Connection connection = null;

	private Channel channel = null;

	public RoutingKeyPro() {
		factory.setHost("106.12.222.85");
		factory.setPort(5672);
		factory.setUsername("guest");
		factory.setPassword("guest");
		factory.setVirtualHost("/");
	}

	public void init() {

		try {
			connection = factory.newConnection();
			channel = connection.createChannel();

			
			channel.queueDeclare(QUEUE_QQ, false, false, false, null);
			channel.queueDeclare(QUEUE_WEIXIN, false, false, false, null);

			
			channel.exchangeDeclare(EXCHANGE_ROUTING, BuiltinExchangeType.DIRECT);

		
			channel.queueBind(QUEUE_QQ, EXCHANGE_ROUTING, RUOTING_KEY);
		} catch (Exception e) {

			e.printStackTrace();
		}
	}

	public void send() {
		
		try {
			for(int i=0 ; i<59999;i++) {
			channel.basicPublish(EXCHANGE_ROUTING, RUOTING_KEY, null, "fine ".getBytes());
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				this.channel.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				this.connection.close();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

	public static void main(String[] args) {
		RoutingKeyPro pro = new RoutingKeyPro();
		pro.init();
		pro.send();
	}
}
